#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "nnie_service.h"
#include "hw_app_config.h"
#include "hw_app_log.h"
#include "opencv_api.h"
using namespace HWApp;

// SAMPLE_SVP_NNIE_MODEL_S                 s_stYoloModel;
// SAMPLE_SVP_NNIE_PARAM_S                 s_stYoloNnieParam;
// SAMPLE_SVP_NNIE_YOLOV3_SOFTWARE_PARAM_S s_stYolov3SoftwareParam;
// SAMPLE_SVP_NNIE_CFG_S                   stNnieCfg_SDC;

int32_t FreeYuvImage(ImageInfo &pstFrame)
{
    if (pstFrame.data) {
        free((void *)(uintptr_t)pstFrame.data);
    }
    return 0;
}

int main(int argc, char* argv[])
{
    const char* imagePath = "./jpeg/640X640.jpg";
    if (argc == 2) {
        imagePath = argv[1];
    }
    printf("imagePath = %s\n", imagePath);
    std::string modelPath = "./model/yolov5_cx_351X_yuv_rgb_80class_inst.wk";
    int ret;
    NNIE nn;
    nn.Init();
    NnCreateParam param = {};
    param.batchNum = 1;
    param.loadModeModel= 1;
    param.modelPath = (char *)modelPath.c_str();
    ret = nn.LoadModel(&param);
    LOG_IF_FAIL(ret == HW_OK, "load model error");
    nn.ParamInit();

    ImageInfo img;
    NNTensor* outTenser;
    std::vector<ObjBox> objBoxs;
    nn.InferenceFile(imagePath, img, objBoxs);
    
    drawObjbox(imagePath, objBoxs);
    FreeYuvImage(img);
	return 0;
}